package com.lanou.musicbox.adapter.seekmusic;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.musicbox.R;
import com.lanou.musicbox.bean.Search_Singer;
import com.lanou.musicbox.utils.VolleySingleton;

import java.util.List;

/**
 * Created by 赵宝龙 on 15/10/26.
 * 搜索_歌手页面Adapter
 */
public class EnterTheSeekMusic_SingerAdapter extends BaseAdapter {
    private Context mContext;
    private List<Search_Singer.DataEntity> data;
    private ImageLoader imageLoader;
    private VolleySingleton volleySingleton;

    public EnterTheSeekMusic_SingerAdapter(List<Search_Singer.DataEntity> data, Context mContext) {
        this.mContext = mContext;
        this.data = data;
        volleySingleton = VolleySingleton.getVolleySingleton(mContext);
        imageLoader = volleySingleton.getImageLoader();
    }

    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return data != null && data.size() > 0 ? data.get(i) : null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view==null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.entertheseekmusic_singer_item, null);
            holder = new ViewHolder();
            holder.pic = (ImageView) view.findViewById(R.id.pic);
            holder.singer_name = (TextView) view.findViewById(R.id.singer_name);
            holder.song_num = (TextView) view.findViewById(R.id.song_num);
            holder.album_num = (TextView) view.findViewById(R.id.album_num);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        Search_Singer.DataEntity ss = data.get(i);
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(holder.pic, R.mipmap.loading, R.mipmap.loading);
        imageLoader.get(ss.getPic_url(), listener);
        Log.e("ZBL", "------------------->" + ss.getSinger_name() + ss.getSong_num() + ss.getAlbum_num());
        if (ss != null) {
            holder.singer_name.setText(ss.getSinger_name());
            holder.song_num.setText(ss.getSong_num() + "");
            holder.album_num.setText(ss.getAlbum_num()+"");
        }
        return view;
    }

    private class ViewHolder {
        private ImageView pic;
        private TextView singer_name, song_num, album_num;
    }
}
